package com.example.helloapplication;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class OtherActivity extends AppCompatActivity {

    private Button backButton;

    @Override
    public void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.other_activity);
        Intent intent = getIntent();
        String data = intent.getStringExtra("extra_data");
        Log.d("SecondActivity",data);
        backButton = findViewById(R.id.back_button);
        backButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Toast.makeText(OtherActivity.this,"It wiil close this activity and back",
                            Toast.LENGTH_SHORT).show();
                    Intent result_Intent = new Intent();
                    result_Intent.putExtra("resultData",2);
                    setResult(RESULT_OK,result_Intent);
                    finish();

            }
        });
    }


    @Override
    public void onBackPressed() {
        Intent result_Intent = new Intent();
        result_Intent.putExtra("resultData",2);
        setResult(RESULT_OK,result_Intent);
        finish();
    }
}
